/*

BlackRabbit - OpenSource IDE.
@author Edward Sarkisyan (edward.sarkisyan@gmail.com)
Use LGPL (http://www.gnu.org/copyleft/lesser.html)

*/

#include "projectitem.h"
#include "../widgets/editor.h"
#include <QMessageBox>
#include <QFileInfo>

ProjectItem::ProjectItem(QTabWidget* tabContainer)
{
    m_language = 0;
    m_topLevelItem = 0;
    m_tabsContainer = tabContainer;
}

ProjectItem::~ProjectItem()
{
    delete m_language;
    delete m_topLevelItem;
}

void ProjectItem::setTopLevelitem(QTreeWidgetItem* topLevel)
{
    if(m_topLevelItem == 0 && topLevel !=0)
        m_topLevelItem = topLevel;
}

QTreeWidgetItem* ProjectItem::topLevelItem()
{
    return m_topLevelItem;
}

void ProjectItem::setAuthor(QString s_author)
{
    m_author = s_author;
}

QString ProjectItem::author()
{
    return m_author;
}

QString ProjectItem::CSV()
{
    return m_CSV;
}

void ProjectItem::setDescription(QString s_description)
{
    m_description = s_description;
}

QString ProjectItem::description()
{
    return m_description;
}

QString ProjectItem::fileName()
{
    return m_fileName;
}

Language* ProjectItem::language()
{
    return m_language;
}

void ProjectItem::setLanguage(Language* s_language)
{
    if(m_language == 0 && s_language != 0)
        m_language = s_language;
}

QString ProjectItem::name()
{
    return m_name;
}

void ProjectItem::setVersion(QString s_version)
{
    m_version = s_version;
}

QString ProjectItem::version()
{
    return m_version;
}

void ProjectItem::addFile(QString s_fileName)
{
    if(!m_files.contains(s_fileName))
        m_files<<s_fileName;
}

void ProjectItem::removeFile(QString s_fileName)
{
    if(!m_files.removeOne(s_fileName))
    {
        /*QMessageBox::critical(this->parent(),
                              QString("Can't remove file %1").arg(fileName),
                              QString("File %1 doesn't exist in this project").arg(fileName)
                              );
                              */
    }
}

bool ProjectItem::openFile(QString path)
{
    return m_language->openFile(m_tabsContainer, path);
}
